﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Threading;
using System.Globalization;

namespace Microsoft.CloudSaver.Web.Infrastructure
{
    public class LocalizedPage:Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            //Code for detecting user-specific page theming.
            if (!string.IsNullOrEmpty(User.Identity.Name))
            {
                var theme=CloudUtils.GetValue(User.Identity.Name,"Theme");
                if (theme != null)
                {
                    Page.Theme = theme;
                }
                else
                {
                    Page.Theme = "default";
                }
            }
        }

        protected override void InitializeCulture()
        {
            try
            {
                HttpCookie c = Request.Cookies["LANG"];
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(c.Value);
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(c.Value);
            }
            catch (Exception)
            {

            }
        }
    }
}